﻿<phone:PhoneApplicationPage 
    x:Class="Locima.SlidingBlock.ImageAreaChooser"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    xmlns:viewModel="clr-namespace:Locima.SlidingBlock.ViewModel"
    xmlns:converters="clr-namespace:Locima.SlidingBlock.Converters"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <phone:PhoneApplicationPage.Resources>
        <viewModel:ImageAreaChooserViewModel x:Key="ImageChooserViewModel"/>
        <converters:BrushOpacityModifier x:Key="BrushOpacityConverter" />
    </phone:PhoneApplicationPage.Resources>

    <Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{StaticResource ImageChooserViewModel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" 
                       Text="{Binding Path=Strings.ApplicationName, Source={StaticResource Localization}}"
                       Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="{Binding Path=Strings.ImageAreaChooserTitle, Source={StaticResource Localization}}"
                       Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Canvas x:Name="ContentCanvas" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Canvas.Clip>
                <RectangleGeometry Rect="0,0,480,480"/>
            </Canvas.Clip>
            <Image x:Name="ImgZoom" Source="{Binding Image}" RenderTransformOrigin="0.5,0.5" CacheMode="BitmapCache" Canvas.ZIndex="-10">
                <toolkit:GestureService.GestureListener>
                    <toolkit:GestureListener
                        PinchStarted="OnPinchStarted"
                        PinchDelta="OnPinchDelta"
                        DragStarted="OnDragStarted"
                        DragDelta="OnDragDelta"
                        />
                </toolkit:GestureService.GestureListener>
                <Image.RenderTransform>
                    <CompositeTransform ScaleX="{Binding Scale}" ScaleY="{Binding Scale}" TranslateX="{Binding ImagePosition.X}" TranslateY="{Binding ImagePosition.Y}"/>
                </Image.RenderTransform>
            </Image>
            <!-- These rectangles create the effect of a "window" through part of the image to see what's going to be used -->
            <Rectangle x:Name="DarkRectLeft" Canvas.ZIndex="10" Fill="{Binding Source={StaticResource PhoneBackgroundBrush},Converter={StaticResource BrushOpacityConverter},ConverterParameter=0.5}" Canvas.Top="{Binding CropTop}" Canvas.Left="0" Width="{Binding CropLeft}" Height="{Binding CropHeight}"/>
            <Rectangle x:Name="DarkRectTop" Canvas.ZIndex="10" Fill="{Binding Source={StaticResource PhoneBackgroundBrush},Converter={StaticResource BrushOpacityConverter},ConverterParameter=0.5}" Canvas.Top="0" Canvas.Left="0" Width="{Binding TotalWidth}" Height="{Binding CropTop}"/>
            <Rectangle x:Name="DarkRectRight" Canvas.ZIndex="10" Fill="{Binding Source={StaticResource PhoneBackgroundBrush},Converter={StaticResource BrushOpacityConverter},ConverterParameter=0.5}" Canvas.Top="{Binding CropTop}" Canvas.Left="{Binding CropRight}" Width="{Binding CropRightToRightEdge}" Height="{Binding CropHeight}"/>
            <Rectangle x:Name="DarkRectBottom" Canvas.ZIndex="10" Fill="{Binding Source={StaticResource PhoneBackgroundBrush},Converter={StaticResource BrushOpacityConverter},ConverterParameter=0.5}" Canvas.Top="{Binding CropBottom}" Canvas.Left="0" Width="{Binding TotalWidth}" Height="{Binding CropBottomToBottomEdge}"/>
            <Border x:Name="CropArea" BorderBrush="{StaticResource PhoneForegroundBrush}" BorderThickness="5" Canvas.Top="{Binding CropTop}" Canvas.Left="{Binding CropLeft}" Width="{Binding CropWidth}" Height="{Binding CropHeight}"/>
        </Canvas>
        <StackPanel x:Name="ToolsPanel" Grid.Row="2">
            <TextBlock x:Name="DebugText" Text="{Binding DebugString}" TextWrapping="Wrap" Visibility="Collapsed"/>
        </StackPanel>
    </Grid>

</phone:PhoneApplicationPage>